import os
import requests
import shutil
import uuid
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import QThread, pyqtSignal
from urllib.parse import urlparse

def detect_ffmpeg():
    return shutil.which("ffmpeg") is not None

class ThumbnailLoader(QThread):
    thumbnail_loaded = pyqtSignal(str, QPixmap)

    def __init__(self, task_id, url):
        super().__init__()
        self.task_id = task_id
        self.url = url

    def run(self):
        try:
            data = requests.get(self.url).content
            pixmap = QPixmap()
            pixmap.loadFromData(data)
            self.thumbnail_loaded.emit(self.task_id, pixmap.scaled(320, 180))
        except Exception as e:
            print(f"Thumbnail load failed: {e}")